var express = require('express');
var router = express.Router();

const db = require('../public/javascripts/db')

router.put('/', function (req, res, next) {
  let info = req.body;
  console.log(info);
  let sql = "update news set news_tit=?, news_desc=?, news_num=? where news_id=?";
  let data = [info.news_tit, info.news_desc, info.news_num,  info.news_id];

  db(sql, data, (result) => {
    console.log(result);
    if (result.affectedRows == 1) {
      res.json({
        code: 200,
        messages: "新闻修改成功"
      })
    } else {
      res.json({
        code: 500,
        messages: "服务器错误"
      })
    }
  })
});

module.exports = router;